﻿/********************************************************************************
     File:																
            Manager.aspx.cs                         
     Description:
            环境信访数据统计管理
     Author:									
            DDBuildTools
            http://DDBuildTools.supesoft.com
     Finish DateTime:
            2013/4/4 0:23:38
     History:
*********************************************************************************/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Model;
using Model.Components;
using FrameWork;
using FrameWork.Components;
using FrameWork.WebControls;

namespace Model.Web.Module.Model.XF
{
    public partial class Manager : System.Web.UI.Page
    {
        Int32 IDX = (Int32)Common.sink("IDX", MethodType.Get, 10, 0, DataType.Int);
        string CMD = (string)Common.sink("CMD", MethodType.Get, 10, 1, DataType.Str);
        protected void Page_Load(object sender, EventArgs e)
        {
            FrameWorkPermission.CheckPagePermission(CMD);
            if (!Page.IsPostBack)
            {
                OnStart();
            }
        }
        private void BindYear()
        {
            int year = DateTime.Now.Year;
            tjYear_Input.Items.Add(new ListItem((year - 1).ToString(), (year - 1).ToString()));
            tjYear_Input.Items.Add(new ListItem(year.ToString(), year.ToString()));
            tjYear_Input.Items.Add(new ListItem((year + 1).ToString(), (year + 1).ToString()));
        }
        
        /// <summary>
        /// 开始操作
        /// </summary>
        private void OnStart()
        {
            XFEntity ut = BusinessFacadeModel.XFDisp(IDX);
            OnStartData(ut);
            BindYear();
            switch (CMD)
            { 
                case "New":
                    TabOptionItem1.Tab_Name = HeadMenuWebControls1.HeadOPTxt = "增加";
                    Hidden_Disp();
                    break;
                case "List":
                    TabOptionItem1.Tab_Name = HeadMenuWebControls1.HeadOPTxt = "查看";
                    Hidden_Input();
                    Button1.Visible = false; 
                    AddEditButton();
                    break;
                case "Edit":
                    TabOptionItem1.Tab_Name = HeadMenuWebControls1.HeadOPTxt = "修改";
                    Hidden_Disp();
                    AddDeleteButton();
                    break;
                case "Delete":
                    ut.DataTable_Action_ = DataTable_Action.Delete;
                    if (BusinessFacadeModel.XFInsertUpdateDelete(ut) > 0)
                    {
                        EventMessage.MessageBox(1, "删除成功", string.Format("删除ID:{0}成功!", IDX), Icon_Type.OK, Common.GetHomeBaseUrl("Default.aspx"));
                    }
                    else {
                        EventMessage.MessageBox(1, "删除失败", string.Format("删除ID:{0}失败!", IDX), Icon_Type.Error, Common.GetHomeBaseUrl("Default.aspx"));
                    }
                    break;
                default :
                    EventMessage.MessageBox(2, "不存在操作字符串!", "不存在操作字符串!", Icon_Type.Error, Common.GetHomeBaseUrl("Default.aspx"));
                    break;
            }
        }

        /// <summary>
        /// 增加修改按钮
        /// </summary>
        private void AddEditButton()
        {
            HeadMenuButtonItem bi = new HeadMenuButtonItem();
            bi.ButtonPopedom = PopedomType.Edit;
            bi.ButtonName = "";
            bi.ButtonUrl = string.Format("?CMD=Edit&IDX={0}", IDX);
            HeadMenuWebControls1.ButtonList.Add(bi);
        }


        /// <summary>
        /// 增加删除按钮
        /// </summary>
        private void AddDeleteButton()
        {
            HeadMenuButtonItem bi = new HeadMenuButtonItem();
            bi.ButtonPopedom = PopedomType.Delete;
            bi.ButtonName = "";
            bi.ButtonUrlType = UrlType.JavaScript;
            bi.ButtonUrl = string.Format("DelData('?CMD=Delete&IDX={0}')", IDX);
            HeadMenuWebControls1.ButtonList.Add(bi);

            HeadMenuButtonItem bi1 = new HeadMenuButtonItem();
            bi1.ButtonPopedom = PopedomType.List;
            bi1.ButtonIcon = "back.gif";
            bi1.ButtonName = "返回";
            bi1.ButtonUrl = string.Format("?CMD=List&IDX={0}", IDX);
            HeadMenuWebControls1.ButtonList.Add(bi1);
        }

        /// <summary>
        /// 初始化数据
        /// </summary>
        /// <param name="ut"></param>
        private void OnStartData(XFEntity ut)
        {
        tjYear_Input.Text = tjYear_Disp.Text = ut.tjYear.ToString();
                tjMonth_Input.Text = tjMonth_Disp.Text = ut.tjMonth.ToString();
                a1_Input.Text = a1_Disp.Text = ut.a1.ToString();
                a2_Input.Text = a2_Disp.Text = ut.a2.ToString();
                a3_Input.Text = a3_Disp.Text = ut.a3.ToString();
                a4_Input.Text = a4_Disp.Text = ut.a4.ToString();
                a5_Input.Text = a5_Disp.Text = ut.a5.ToString();
                a6_Input.Text = a6_Disp.Text = ut.a6.ToString();
                a7_Input.Text = a7_Disp.Text = ut.a7.ToString();
                a8_Input.Text = a8_Disp.Text = ut.a8.ToString();
                a9_Input.Text = a9_Disp.Text = ut.a9.ToString();
                a10_Input.Text = a10_Disp.Text = ut.a10.ToString();
                a11_Input.Text = a11_Disp.Text = ut.a11.ToString();
                a12_Input.Text = a12_Disp.Text = ut.a12.ToString();
                //tbr_Input.Text = tbr_Disp.Text = ut.tbr.ToString();
                //phone_Input.Text = phone_Disp.Text = ut.phone.ToString();
                //tjTime_Input.Text = tjTime_Disp.Text = ut.tjTime.ToString();
                
        }

        /// <summary>
        /// 隐藏输入框
        /// </summary>
        private void Hidden_Input()
        {
        tjYear_Input.Visible = false;
        tjMonth_Input.Visible = false;
        a1_Input.Visible = false;
        a2_Input.Visible = false;
        a3_Input.Visible = false;
        a4_Input.Visible = false;
        a5_Input.Visible = false;
        a6_Input.Visible = false;
        a7_Input.Visible = false;
        a8_Input.Visible = false;
        a9_Input.Visible = false;
        a10_Input.Visible = false;
        a11_Input.Visible = false;
        a12_Input.Visible = false;
        //tbr_Input.Visible = false;
        //phone_Input.Visible = false;
        //tjTime_Input.Visible = false;
        
        }

        /// <summary>
        /// 隐藏显示框
        /// </summary>
        private void Hidden_Disp()
        {
        tjYear_Disp.Visible = false;
        tjMonth_Disp.Visible = false;
        a1_Disp.Visible = false;
        a2_Disp.Visible = false;
        a3_Disp.Visible = false;
        a4_Disp.Visible = false;
        a5_Disp.Visible = false;
        a6_Disp.Visible = false;
        a7_Disp.Visible = false;
        a8_Disp.Visible = false;
        a9_Disp.Visible = false;
        a10_Disp.Visible = false;
        a11_Disp.Visible = false;
        a12_Disp.Visible = false;
        //tbr_Disp.Visible = false;
        //phone_Disp.Visible = false;
        //tjTime_Disp.Visible = false;
        
        }

        /// <summary>
        /// 增加/修改事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {
        
            int tjYear_Value = (int)Common.sink(tjYear_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int tjMonth_Value = (int)Common.sink(tjMonth_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a1_Value = (int)Common.sink(a1_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a2_Value = (int)Common.sink(a2_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a3_Value = (int)Common.sink(a3_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a4_Value = (int)Common.sink(a4_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a5_Value = (int)Common.sink(a5_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a6_Value = (int)Common.sink(a6_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a7_Value = (int)Common.sink(a7_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a8_Value = (int)Common.sink(a8_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a9_Value = (int)Common.sink(a9_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a10_Value = (int)Common.sink(a10_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a11_Value = (int)Common.sink(a11_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a12_Value = (int)Common.sink(a12_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);

            DateTime? tjTime_Value = DateTime.Now;
                
            XFEntity ut = BusinessFacadeModel.XFDisp(IDX);
            
            ut.tjYear = tjYear_Value;
            ut.tjMonth = tjMonth_Value;
            ut.a1 = a1_Value;
            ut.a2 = a2_Value;
            ut.a3 = a3_Value;
            ut.a4 = a4_Value;
            ut.a5 = a5_Value;
            ut.a6 = a6_Value;
            ut.a7 = a7_Value;
            ut.a8 = a8_Value;
            ut.a9 = a9_Value;
            ut.a10 = a10_Value;
            ut.a11 = a11_Value;
            ut.a12 = a12_Value;
            //ut.tbr = tbr_Value;
            //ut.phone = phone_Value;
            ut.tjTime = tjTime_Value;
            ut.tjdep = UserData.GetUserDate.U_GroupID;
            if (CMD == "New")
            {
                ut.DataTable_Action_ = DataTable_Action.Insert;
            }
            else if (CMD == "Edit")
            {
                ut.DataTable_Action_ = DataTable_Action.Update;
            }
            else
            {
                EventMessage.MessageBox(2, "不存在操作字符串!", "不存在操作字符串!", Icon_Type.Error, Common.GetHomeBaseUrl("Default.aspx"));
            }
            Int32 rInt = BusinessFacadeModel.XFInsertUpdateDelete(ut);
            if ( rInt> 0)
            {
                string OpTxt = string.Format("增加环境信访数据统计成功!(ID:{0})", rInt);
                if (ut.DataTable_Action_ == DataTable_Action.Update)
                    OpTxt = string.Format("修改环境信访数据统计成功!(ID:{0})",IDX);
                EventMessage.MessageBox(1, "操作成功", OpTxt, Icon_Type.OK, Common.GetHomeBaseUrl("Default.aspx"));
            }
            else if (rInt == -2)
            {
                EventMessage.MessageBox(1, "操作失败", "操作失败,存在相同的键值(用户名/数据)!", Icon_Type.Alert, Common.GetHomeBaseUrl("Default.aspx"));
            }
            else
            {
                EventMessage.MessageBox(1, "操作失败", string.Format("操作失败,返回值:{0}!", rInt), Icon_Type.Error, Common.GetHomeBaseUrl("Default.aspx"));
            }
        }

       
    }
}
